package com.shylock.as.util;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;


public class JedisUtil {
    public static final String HOST="120.77.179.231";
    public static final Integer PORT=6380;
    public static final String PASS="xjl920912";
    private static Jedis client;
    static {
        JedisPool pool=new JedisPool(HOST,PORT);
        client=pool.getResource();
        client.auth(PASS);
    }
    //新增
    public static void addStr(String key,String val,long seconds){
        client.setex(key,seconds,val);
    }
    public static void addSet(String key,String val){
        client.sadd(key,val);
    }
    //查询
    public static String getStr(String key){
        return client.get(key);
    }
    public static boolean checkSet(String key,String val){
        return client.sismember(key,val);
    }
    //校验
    public static boolean checkKey(String key){
        return client.exists(key);
    }
    //返回剩余有效期
    public static long ttl(String key){
        return client.ttl(key);
    }
    //删除
    public static boolean delKey(String key){
        return client.del(key)>0;
    }
    public static boolean delSet(String key,String val){
        return client.srem(key,val)>0;
    }
    //设置key的有效期
    public static void expire(String key,long seconds){
        client.expire(key, seconds);
    }
}